
import java.util.Random;




public class Map {

    private int[][] map;
    public int x = 0, y = 0;

    public Map(int x, int y){
        if(x<25||y<25){
           throw new java.lang.IndexOutOfBoundsException("Failed");
        }
        this.x = x;
        this.y = y;
        map = new int[this.x][this.y];
        for(int z=0; z<x; z++){
            for(int v=0; v<y; v++){
                map[z][v] = 0;
            }
        }
        for(int z=0; z<x; z++){
            map[0][z] = 1;
            map[z][0] = 1;
            map[z][x-1] = 1;
            map[x-1][z] = 1;
        }
        Random r = new Random();
        for(int z=0; z<12; z++){
            map[r.nextInt(x-2)+1][r.nextInt(x-2)+1] = 2;
        }
    }

    public boolean setLocation(int x, int y, int newid) {
        if (x >= this.x || y >= this.y || x < 0 || y < 0) {
            throw new java.lang.IndexOutOfBoundsException("Failed");
        }
        int temp = map[x][y];
        if (temp == newid) {
            return false;
        } else {
            map[x][y] = newid;
            return true;
        }
    }

    public int get(int x, int y) {
        if (x >= this.x || y >= this.y || x < 0 || y < 0) {
            throw new java.lang.IndexOutOfBoundsException("Failed");
        }
        return map[x][y];
    }

    public int[][] getMap(){
        return map;
    }

}
